import React from "react";
import ReactDOM from "react-dom";

class Demo extends React.Component {
  state = {
    time: 'xxx'
  }
 
  render() {
    return (
      <div>
        <h2>我是类组件，当前时间是</h2>
        <p>{this.state.time}</p>
        {/* <button onClick={this.setState({time: 'yyy'})}>获取最新时间</button> */}
        <button onClick={()=>{this.setState({time:new Date().toISOString()})}}>获取最新时间</button>
      </div>
    )
  }
}

ReactDOM.render(<Demo />,document.getElementById('root'))